I am using react with typescript in my project and also I am doing snapshot testing but when I run npm test command in vscode terminal I am getting error which I have attached in the attachement. could you please let me know what should I do so that all the test case run successfully or any other thing I need to configure
Here is my package.json
{
"name": "vcc-collaboration-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fluentui/react": "^8.42.1",
"@fluentui/react-file-type-icons": "^8.5.6",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/react-test-renderer": "^17.0.1",
"ag-grid-community": "^26.2.0",
"ag-grid-react": "^26.2.0",
"axios": "^0.24.0",
"babel-jest": "^26.6.0",
"jest": "^26.6.0",
"jest-watch-typeahead": "^1.0.0",
"moment": "^2.29.1",
"node-sass": "^6.0.1",
"react": "^17.0.2",
"react-bootstrap": "^2.0.2",
"react-dom": "^17.0.2",
"react-dropzone": "^11.4.2",
"react-grid": "^4.0.4",
"react-icons": "^4.3.1",
"react-router-dom": "^5.0.0",
"react-scripts": "4.0.3",
"react-test-renderer": "^17.0.2",
"vcc-ui": "^2.11.0",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.7",
"@types/react": "^17.0.35",
"@types/react-dom": "^17.0.11",
"@types/react-dropzone": "^5.1.0",
"@types/react-router": "^5.1.17",
"@types/react-router-dom": "^5.3.2",
"typescript": "^4.5.2"
}
}
EngineeringArea.test.tsx
import React from "react";
import * as ShallowRenderer from "react-test-renderer/shallow";
import EngineeringArea from "./EngineeringArea";
describe("EngineeringArea Screen", () => {
it("EngineeringArea Screen renders correctly", () => {
const renderer = ShallowRenderer.createRenderer();
const component = renderer.render(<EngineeringArea />);
expect(component).toMatchSnapshot();
});
});
Last answer was wrong. Here's the correct answer. https://github.com/facebook/create-react-app/issues/11043#issuecomment-942472592
Had this error come up. My answer was using nvm to switch from node's current release (my system default) to its LTS (16.14.0) with nvm use 16
Also got this error message when trying to test. Changing node version worked for me. Here is link to the article: https://github.com/facebook/create-react-app/issues/11792
I faced this issue while I was trying to create a new React Application using CRA with npx.
I followed what Matt suggested in his answer but jest started throwing an error saying, it's better to remove any babel-jest dependency, which is weird but I guess jest-watch-typehead` uses babel maybe (it's a wild guess, I have not checked).
Anyway, here's what I did based on the suggestion I got on console from the error thrown by babel-jest.
package-lock.json file.node_modules/.npm i.App.test.js, so I simply imported and it worked.You need to install specifically v0.6.5 of jest-watch-typeahead
npm i -D --exact jest-watch-typeahead@0.6.5